package net.suncaper.mvc.common.utils;

import net.suncaper.mvc.model.domain.Hotel;
import net.suncaper.mvc.model.domain.Order;
import net.suncaper.mvc.model.domain.Review;
import net.suncaper.mvc.model.domain.Room;
import net.suncaper.mvc.model.domain.User;
import net.suncaper.mvc.model.vo.HotelVO;
import net.suncaper.mvc.model.vo.OrderVO;
import net.suncaper.mvc.model.vo.ReviewVO;
import net.suncaper.mvc.model.vo.RoomVO;
import net.suncaper.mvc.model.vo.UserVO;

import java.util.ArrayList;
import java.util.List;

/**
 * 实体类转换工具类
 */
public class EntityConverter {

    /**
     * 将User实体类转换为UserVO
     */
    public static UserVO convertToUserVO(User user) {
        if (user == null) {
            return null;
        }
        UserVO userVO = new UserVO();
        userVO.setUserId(user.getUserId());
        userVO.setEmail(user.getEmail());
        userVO.setAvatar(user.getAvatar());
        userVO.setStatus(user.getStatus());
        userVO.setGender(user.getGender());
        userVO.setAge(user.getAge());
        userVO.setCreateTime(user.getCreateTime());
        return userVO;
    }

    /**
     * 将User列表转换为UserVO列表
     */
    public static List<UserVO> convertToUserVOList(List<User> users) {
        if (users == null || users.isEmpty()) {
            return new ArrayList<>();
        }
        List<UserVO> userVOList = new ArrayList<>();
        for (User user : users) {
            userVOList.add(convertToUserVO(user));
        }
        return userVOList;
    }

    /**
     * 将Hotel实体类转换为HotelVO
     */
    public static HotelVO convertToHotelVO(Hotel hotel) {
        if (hotel == null) {
            return null;
        }
        HotelVO hotelVO = new HotelVO();
        hotelVO.setHotelName(hotel.getHotelName());
        hotelVO.setCountry(hotel.getCountry());
        hotelVO.setCity(hotel.getCity());
        hotelVO.setImageUrl(hotel.getImageUrl());
        hotelVO.setLongitude(hotel.getLongitude());
        hotelVO.setLatitude(hotel.getLatitude());
        hotelVO.setRating(hotel.getRating());
        return hotelVO;
    }

    /**
     * 将Hotel列表转换为HotelVO列表
     */
    public static List<HotelVO> convertToHotelVOList(List<Hotel> hotels) {
        if (hotels == null || hotels.isEmpty()) {
            return new ArrayList<>();
        }
        List<HotelVO> hotelVOList = new ArrayList<>();
        for (Hotel hotel : hotels) {
            hotelVOList.add(convertToHotelVO(hotel));
        }
        return hotelVOList;
    }

    /**
     * 将Room实体类转换为RoomVO
     */
    public static RoomVO convertToRoomVO(Room room) {
        if (room == null) {
            return null;
        }
        RoomVO roomVO = new RoomVO();
        roomVO.setRoomType(room.getRoomType());
        roomVO.setHotelName(room.getHotelName());
        roomVO.setImageUrl(room.getImageUrl());
        roomVO.setPrice(room.getPrice());
        roomVO.setAvailableCount(room.getAvailableCount());
        roomVO.setBreakfast(room.getBreakfast());
        return roomVO;
    }

    /**
     * 将Room列表转换为RoomVO列表
     */
    public static List<RoomVO> convertToRoomVOList(List<Room> rooms) {
        if (rooms == null || rooms.isEmpty()) {
            return new ArrayList<>();
        }
        List<RoomVO> roomVOList = new ArrayList<>();
        for (Room room : rooms) {
            roomVOList.add(convertToRoomVO(room));
        }
        return roomVOList;
    }

    /**
     * 将Order实体类转换为OrderVO
     */
    public static OrderVO convertToOrderVO(Order order) {
        if (order == null) {
            return null;
        }
        OrderVO orderVO = new OrderVO();
        orderVO.setId(order.getId());
        orderVO.setCreateTime(order.getCreateTime());
        orderVO.setPayTime(order.getPayTime());
        orderVO.setCancelTime(order.getCancelTime());
        orderVO.setUserId(order.getUserId());
        orderVO.setAmount(order.getAmount());
        orderVO.setPaymentMethod(order.getPaymentMethod());
        orderVO.setRoomType(order.getRoomType());
        orderVO.setHotelName(order.getHotelName());
        return orderVO;
    }

    /**
     * 将Order列表转换为OrderVO列表
     */
    public static List<OrderVO> convertToOrderVOList(List<Order> orders) {
        if (orders == null || orders.isEmpty()) {
            return new ArrayList<>();
        }
        List<OrderVO> orderVOList = new ArrayList<>();
        for (Order order : orders) {
            orderVOList.add(convertToOrderVO(order));
        }
        return orderVOList;
    }

    /**
     * 将Review实体类转换为ReviewVO
     */
    public static ReviewVO convertToReviewVO(Review review) {
        if (review == null) {
            return null;
        }
        ReviewVO reviewVO = new ReviewVO();
        reviewVO.setReviewTime(review.getReviewTime());
        reviewVO.setUserId(review.getUserId());
        reviewVO.setRating(review.getRating());
        reviewVO.setContent(review.getContent());
        reviewVO.setHotelName(review.getHotelName());
        return reviewVO;
    }

    /**
     * 将Review列表转换为ReviewVO列表
     */
    public static List<ReviewVO> convertToReviewVOList(List<Review> reviews) {
        if (reviews == null || reviews.isEmpty()) {
            return new ArrayList<>();
        }
        List<ReviewVO> reviewVOList = new ArrayList<>();
        for (Review review : reviews) {
            reviewVOList.add(convertToReviewVO(review));
        }
        return reviewVOList;
    }
} 